<template>
  <div id="backcont">
    <div class="Quiz-content">
      <div class="login-cont">
        <div class="MBTI-title">MBTI职业性格测试</div>
        <div class="MBTI-user">
          <p>学号</p>
          <el-input clearable v-model="studentId" class="inptflex" placeholder="请输入学号" />
        </div>
         <div class="MBTI-user">
          <p>密码</p>
          <el-input show-password v-model="passwrod" class="inptflex" placeholder="请输入密码" />
        </div>
        <!-- 登录和注册按钮的切换 -->
         <el-button @click="toRegist" size="small" class="reg-views">注册</el-button>
        <!-- 登录或注册按钮的提交 -->
        <el-button @click="signin" class="denglu-btn">登录</el-button>

        <el-button @click="to_m" class="m-btn">管理员登陆</el-button>

     
      </div>
    </div>
  </div>
 
</template>


<script>
import { ElMessage } from 'element-plus'
import {useRouter} from 'vue-router'
import { reactive,toRefs,getCurrentInstance  } from 'vue'
export default{
  setup(){
    const {proxy} = getCurrentInstance()//取到全局属性和方法
    const router = useRouter()
    const user = reactive({
      studentId:'',
      passwrod:'',

    })

    //登录,进行传值在request.js文件中收
    const signin = async()=>{
      const obj = {
        studentId:  user.studentId,
        password:   user.passwrod
      }

      try{
        const res = await new proxy.$request(proxy.$urls.m().login,obj).modepost()
       

       if(res.status = 200){
         ElMessage('登录成功')
         //登录界面
          router.push({
          path: "/index",
      });
      console.log(res)
         localStorage.setItem('sno',res.data.studentId),
         localStorage.setItem('name',res.data.StudentName),
         localStorage.setItem('class',res.data.classId),
         localStorage.setItem('toeken',res.data.AccessSecret)

      }else{
        ElMessage('请重新输入')
      }

      }catch(e){
         ElMessage('请重新输入')
        // new proxy.$tips('服务器错误').message()
      }

    }

   //注册
   const toRegist = ()=>{
     router.push({
        name: "v_regist",
      });
   };

    const to_m = ()=>{
     router.push({
        name: "m_login",
      });
   };

   
    return{to_m,...toRefs(user), signin, toRegist, proxy}
  }
}

</script>


<style >

</style>
